package gov.pbc.nn.kjgl.jfcr.dao;

import java.util.Collection;

import gov.pbc.nn.core.dao.AbstractHibernateDao;
import gov.pbc.nn.kjgl.entity.ComputerRoomEntryType;

import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import com.bstek.dorado.annotation.DataResolver;
import com.bstek.dorado.data.entity.EntityState;
import com.bstek.dorado.data.entity.EntityUtils;
import com.bstek.dorado.data.provider.Page;

/**
 * ComputerRoomEntryType的数据库操作
 * 
 * @author jack.zhao
 * 
 */
@Repository
public class ComputerRoomEntryTypeDao extends AbstractHibernateDao {
	/**
	 * 使用dao 分页
	 * 
	 * @param page
	 */
	public void getComputerRoomEntryTypePage(Page<ComputerRoomEntryType> page) {
		DetachedCriteria query = DetachedCriteria.forClass(ComputerRoomEntryType.class);
		query.add(Restrictions.or(Restrictions.eq("invalid", false), Restrictions.isNull("invalid")));
		this.pagingQuery(page, query);
	}

	/**
	 * 使用dao保存
	 * 
	 * @param lists
	 */
	public void updateComputerRoomEntryType(Collection<ComputerRoomEntryType> lists) {
		for (ComputerRoomEntryType entity : lists) {
			EntityState state = EntityUtils.getState(entity);
			if (state.equals(EntityState.NEW)) {
				this.save(entity);
			} else if (state.equals(EntityState.DELETED)) {
				this.delete(entity);
			} else if (state.equals(EntityState.MODIFIED)) {
				this.update(entity);
			}
		}
	}

}
